Skip to content

fix(source): handle pointer-slice List items in extractItems#303

Merged
golgoth31 merged 3 commits into
mainfrom
fix/extractitems-pointer-slice
Jun 18, 2026
Merged

fix(source): handle pointer-slice List items in extractItems#303
golgoth31 merged 3 commits into
mainfrom
fix/extractitems-pointer-slice

Conversation

@golgoth31

Copy link
Copy Markdown
Owner

Summary

After the scheme fix (#301), the manager panicked once the Istio source actually returned items:

panic: interface conversion: **v1.Gateway is not client.Object: missing method DeepCopyObject
  internal/controller/source.extractItems  cycle.go:164

extractItems did v.Index(i).Addr().Interface().(client.Object). That works for value slices ([]TAddr()*T), but generated clients like istio client-go use pointer slices (GatewayList.Items []*Gateway); Addr()-ing a *T element yields **T, which is not a client.Object → panic, crashing the SourceReconciler runnable.

Fix

  • Detect the element kind: for []*T use the element directly; for []T take its address.
  • Skip (don't panic) on a non-client.Object element so a stray type can't crash the runnable, and return the skip count so the caller logs it (a silent skip would shrink discovery and skew the atomic-wipe guard — logger.Error is the existing convention in this file).

Adds white-box tests for value-slice (corev1.ServiceList), pointer-slice (istio GatewayList, which reproduced the panic), and the no-Items case.

Test plan

  • TestExtractItems_PointerSlice (istio) — was panicking, now passes
  • TestExtractItems_ValueSlice (corev1), TestExtractItems_NoItemsField
  • existing source cycle tests pass; go test -race, golangci-lint clean
  • Review panel (exec-trace / silent-failure / code) — RAS; silent-skip finding addressed via skip-count logging

🤖 Generated with Claude Code

golgoth31 and others added 3 commits June 18, 2026 21:23
extractItems took the address of each reflected Items element and asserted
client.Object. That assumes value slices ([]T → *T). Generated clients like
istio client-go use pointer slices ([]*T); Addr()-ing those yields **T,
which is not a client.Object, so the SourceReconciler panicked once the
istio Gateway scheme was registered and the list actually returned items:

  panic: interface conversion: **v1.Gateway is not client.Object:
         missing method DeepCopyObject

Detect the element kind: for []*T use the element directly, for []T take its
address. Skip (don't panic) on a non-client.Object element so a stray type
can't crash the runnable.

Adds white-box tests for both value-slice (corev1) and pointer-slice
(istio GatewayList) lists.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Review (silent-failure): extractItems now returns how many elements it
skipped; the cycle caller logs it. A silent skip would shrink discovery
and skew the atomic-wipe guard with no trace — should never happen for
registered source types, but no longer invisible if it does.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@golgoth31 golgoth31 merged commit f399d8f into main Jun 18, 2026
2 checks passed
@golgoth31 golgoth31 deleted the fix/extractitems-pointer-slice branch June 18, 2026 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant